﻿using AutoMapper;
using B.S.Traceability.Domain;
using B.S.Traceability.Error;
using B.S.Traceability.Infrastructure.Interface;
using B.S.Traceability.Read.API.Application.Commends.Company;
using B.S.Traceability.Read.API.Application.Commends.Processs;
using MediatR;
using static System.Runtime.InteropServices.JavaScript.JSType;

namespace B.S.Traceability.Read.API.Application.CommendHandlers.Processs
{



    public class GetProcessCommendHandlers : IRequestHandler<GetProcessCommends, APIResult<List<Process>>>
    {

        private readonly IBaseRepository<Process> processRepository;
        private readonly IMapper mapper;

        public GetProcessCommendHandlers(IBaseRepository<Process> processRepository, IMapper mapper)
        {
            this.processRepository = processRepository;
            this.mapper = mapper;
        }







        /// <summary>
        /// 显示深加工信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<APIResult<List<Process>>> Handle(GetProcessCommends request, CancellationToken cancellationToken)
        {
            APIResult<List<Process>> result = new APIResult<List<Process>>();
          
            var list = processRepository.GetAllAsync().Result.ToList();

            result.Code = APIEnum.查询成功;
            result.Msg = "查询成功";
            result.data = list;
            //     var firms=mapper.Map<List<Companys>>(list.ToList());

            return await Task.FromResult(result);
        }
    }
}
